
import 'package:shared_preferences/shared_preferences.dart';

class CnUserDefaultCacheHelper
{

 //
  static const String kUserId = 'userId'; 
  //鉴权串
  static const String kAuthToken = 'token'; 

    static const String KCountry = 'country'; 


  static const String kGetAppConfigVerKey = 'ver';

  

   //读取本地数据
  static Future<String> getUserDefault(String key) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  var ver = prefs.getString(key); //读取mainphone的值
  return ver ?? ''; //返回
  }

  static Future<dynamic> getUserDefaultAny(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var ver = prefs.get(key); //读取mainphone的值
    return ver; //返回
  }

  //读取数据
  static Future<String> getAuthToken() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String? authcode = prefs.getString(kAuthToken); //读取authcode的值
  return authcode ?? ''; //返回
  }

 //读取App配置数据
  static Future<String> getAppConfigVer() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  var ver = prefs.getString(kGetAppConfigVerKey); //读取mainphone的值
  return ver ?? ''; //返回
  }

  //读取用户数据
  static Future<String> getUserId() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  var userId = prefs.getString(kUserId); //读取mainphone的值
  return userId ?? ''; //返回
  }

  static Future<String> getCountry() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  var userId = prefs.getString(KCountry); //读取mainphone的值
  return userId ?? ''; //返回
  }

  //读取bool值类型数据
  static Future<bool> getBoolValue(String key) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  var value = prefs.getBool(key); //读取mainphone的值
  return value ?? false; 
  }


//读取网络必传登录数据
  // static Future<Map> getNetData() async {
  // SharedPreferences prefs = await SharedPreferences.getInstance(); 
  // var authToken = prefs.getString(kAuthToken); //读取authcode的值
  // var userId = prefs.getString(kUserId); //读取authstr的值 
  //  authToken = '1d9ad274f19875211e5ac960814f2445';
  // userId = '1820600260071322072201130o';
  // return { 'authcode':authToken,'userId':userId};
  // // return {'mainphone':mainphone??'','authcode':authcode??'','authstr':authstr??''};
  // }


  //写入数据
  static setUserDefault(String key, dynamic val) async 
  {
    // SharedPreferences.setMockInitialValues({});
    SharedPreferences prefs = await SharedPreferences.getInstance(); //定义一个SharedPreferences类型
    await prefs.setString(key, val);//写入具体的数据
  }

//写入bool值数据
   static setBoolDefault(String key, dynamic val) async 
  {
    SharedPreferences prefs = await SharedPreferences.getInstance(); //定义一个SharedPreferences类型
    await prefs.setBool(key, val);//写入具体的数据
  }

  //写入int值数据
  static setIntDefault(String key, int val) async
  {
    SharedPreferences prefs = await SharedPreferences.getInstance(); //定义一个SharedPreferences类型
    await prefs.setInt(key, val);//写入具体的数据
  }
  static Future<int>  getIntDefault(String key, int val) async
  {
    SharedPreferences prefs = await SharedPreferences.getInstance(); //定义一个SharedPreferences类型
    return prefs.getInt(key)??val;//写入具体的数据
  }

}